package org.example;

import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;

public class MyRunnable<V> implements Runnable{
    Callable<V> callable;
    CountDownLatch countDownLatch;
    V result;

    public MyRunnable(Callable<V> callable,CountDownLatch countDownLatch) {
        this.callable = callable;
        this.countDownLatch=countDownLatch;
    }

    public V getResult() {
        return result;
    }

    @Override
    public void run() {
        V callResult = null;
        try {
            callResult = callable.call();
        } catch (Exception e) {
            e.printStackTrace();
            countDownLatch.countDown();
        }
        result=callResult;
        countDownLatch.countDown();
    }
}
